package lock.synchronize;

import generic.Person;

/**
 * @author zhangxin
 * @date 2020/11/6
 */
public class ClassTest {

    private static Person person = new Person();


    public synchronized static void tttt() {
        Thread thread = new Thread(() -> {

            System.out.println("Person.class");

            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        thread.start();
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {

            synchronized (ClassTest.class) {
                System.out.println("Person.class1");

                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        thread.start();

        tttt();

        Thread.sleep(1000);
        Thread thread2 = new Thread(() -> {

            synchronized (person) {
                System.out.println("person instance");

                // try {
                //     Thread.sleep(3000);
                // } catch (InterruptedException e) {
                //     e.printStackTrace();
                // }
            }
        });

        thread2.start();

        Thread.sleep(5000);
    }
}
